package com.cloud.bssp.netty.EventLoopGroup;

import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.EventExecutor;

import java.io.IOException;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @description： TODO
 * @author：weirx
 * @date：2021/11/9 14:22
 * @version：3.0
 */
public class TestEventLoopGroup {

    public static void main(String[] args) throws InterruptedException {
        //构造方法可以指定线程数，默认不设置会首先根据Netty的环境变量，否则根据线程核心数*2，最小为1
        NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(2);

        // 执行普通任务
        nioEventLoopGroup.next().execute(TestEventLoopGroup::print);

        // 执行定时任务,延后一秒打印
        System.out.println(new Date());
        nioEventLoopGroup.next().schedule(TestEventLoopGroup::print, 1000, TimeUnit.MILLISECONDS);

    }

    private static void print() {
        System.out.println(new Date() + " " +Thread.currentThread());
    }
}
